<html>
<head><meta charset="utf-8"><title>compiler optimizes too well · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html">compiler optimizes too well</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="237870849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237870849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237870849">(May 07 2021 at 18:40)</a>:</h4>
<p>I'm trying to write a codegen test with <code>// CHECK-LABEL:</code>... and then a second test with another label. And it doesn't work because the second test gets optimized so well that it just ends up as an alias to the first one in the IR. It is a nice problem to have <span aria-label="joy" class="emoji emoji-1f602" role="img" title="joy">:joy:</span></p>



<a name="237872188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237872188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237872188">(May 07 2021 at 18:51)</a>:</h4>
<p>you can put them in different files maybe</p>



<a name="237874818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237874818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237874818">(May 07 2021 at 19:08)</a>:</h4>
<p>Any idea how to check the absence of function calls? <code>CHECK-NOT: call</code> doesn't work in the presence of <code>tail call void @llvm.experimental.noalias.scope.decl(metadata !14)</code></p>



<a name="237876168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237876168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237876168">(May 07 2021 at 19:17)</a>:</h4>
<p>either check for a specific instruction sequence (CHECK/CHECK-NEXT) or check for absence of calls to specific functions.</p>



<a name="237939658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237939658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237939658">(May 08 2021 at 08:54)</a>:</h4>
<p>Do we have any test type that can check assembly output?</p>



<a name="237941027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237941027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237941027">(May 08 2021 at 09:16)</a>:</h4>
<p>src/test/assembly iirc</p>



<a name="237941041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237941041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237941041">(May 08 2021 at 09:17)</a>:</h4>
<p>Or maybe there was a codegen test annotation of some sort don't remember can't check not at a computer but definitely exists.</p>



<a name="237944685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237944685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237944685">(May 08 2021 at 10:18)</a>:</h4>
<p>That does what it's supposed to but I'm not getting the results that I want.<br>
When I isolate the code I'm trying to optimize into a <code>#[inline(never)]</code> function in a <code>#[bench]</code> suite then <code>objdump -C</code> shows a small function with ~10 instructions. No register saves or anything.<br>
When I test the same function in an assembly test it produces much worse code including several loops, push/pop and other stuff.</p>
<p>Does that have something to do with calling conventions or some compiler flag or does the benchmark look too rosy because it can just optimize everything away despite <code>inline(never)</code> and <code>black_box</code>?</p>



<a name="237952661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/compiler%20optimizes%20too%20well/near/237952661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/compiler.20optimizes.20too.20well.html#237952661">(May 08 2021 at 12:35)</a>:</h4>
<p>hm, after shuffling things into a closure and running with the same target-cpu things look a bit more similar but there still is a loop that gets optimized away in the benchmark but not in the assembly test <span aria-label="oh no" class="emoji emoji-1f615" role="img" title="oh no">:oh_no:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>